/*******************************************************************************

  Paying Outsourced Labor: Direct Evidence from Linked Temp Agency-Worker-Client Data

  By Andres Drenik, Simon Jäger, Pascuel Plotkin and Benjamin Schoefer
	January 7th, 2021

	DESCRIPTION: Re-shapes and Cleans Dataset For CBA Coverage by industry

*******************************************************************************/




/********************************************************************************
***** Preliminaries
********************************************************************************/
set more off
cap log close
local curr_date = c(current_date)
log using "${logs}/12_CBA_collapse_dta`curr_date'", replace


/****************************************************************************************
* Collapse the CBA coverage by 4 Digit - Industry
****************************************************************************************/

*Merge temp and regular worker datasets
use "${intermediate_data_emp}/newnewSIPAConvencionadosBy4DigitSector.dta", clear

*Change date format
gen daily = dofm(date)
gen year = year(daily)
drop daily

*Keep relevant years
drop if year < 2009
drop if year > 2017

gen share_cov = conv_equal_1 / worker

collapse (mean) share_cov, by(ciiu_4)

rename ciiu_4 ciiu_4_user

save "${intermediate_data_clea}/cba_coverage_by_industry.dta", replace

log close
